/*
 * disk.h
 *
 *  Created on: Jul 11, 2009
 *      Author: mosh
 */

#include "constants.h"

#ifndef DISK_H_
#define DISK_H_


class Disk{
private:
	int _disk_fd;
	int _blk_size;        //in bytes
	int _num_of_inodes;
	int _disk_size;       //in bytes
	bool _new;

	void calcStuff(general_data *g);

	void write_in_blcok(int block_number,int inBlockOffset,char* input);
	int* set_free_block_list(general_data *g);

public:
	Disk();
	Disk(string file_name);
	general_data *read_general_data();
	void writeGeneralData(general_data *g);
	int getFirsFreeBlock();
	int getLastFreeBlock();
	void write_block(int block_number,char *input);
	char *read_block(int block_number);
	char *read_inode(int i_number);
	void write_inode(int i_number,char *inode);
	void read_block_to_buffer(int block_number,char *buffer);
	bool isNew();
	int getBlockSize();


};

class FreeBlockManager{
private:
	Disk *_disk;
public:
	FreeBlockManager(Disk* d);
	int pop();
	int push(int block_number);
};

class InodeManager{
private:
	FreeBlockManager *_manager;
	Disk *_disk;
public:
	InodeManager(FreeBlockManager *manager,Disk *disk);
	void construct_free_inode_list();
	int pop();
	int push(int block_number);
};


#endif /* DISK_H_ */
